Programming With QuickTime Sprites

| Previous | Chapter Contents | Chapter Top | Next |

Disposing of a Sprite Animation

When your application has finished displaying a sprite animation, you should do the following things in the order shown:

  1. Dispose of the sprite world associated with the animation. (You need to do this first.) Disposing of a sprite world automatically destroys the sprites in the sprite world.
  2. Dispose of the sprite image data.
  3. Dispose of graphics worlds associated with the sprite animation.

In the sample application, main calls the sample code function DisposeEverything to dispose of sprite-related structures. This function, shown in Listing 0-5 , iterates through the sprites, disposing of each sprite's image data. Then, DisposeEverything calls DisposeSpriteWorld to dispose of the sprite world and all of the sprites in it. Finally, the function calls DisposeGWorld to dispose of the graphics world associated with the sprite world.

Listing 5 Disposing of sprites and the sprite world

// constants
#define kNumSprites 4
#define kNumSpaceShipImages 24

// global variables
SpriteWorld gSpriteWorld = nil;
Sprite gSprites[kNumSprites];
Handle gCompressedPictures[kNumSpaceShipImages];
ImageDescriptionHandle gImageDescriptions[kNumSpaceShipImages];

void DisposeEverything (void)
{
    short i;
    // dispose of the sprite world and associated graphics world
    if (gSpriteWorld)
        DisposeSpriteWorld (gSpriteWorld);
    
    // dispose of each sprite's image data
    for (i = 0; i < kNumSprites; i++)
    {
        if (gCompressedPictures[i])
            DisposeHandle (gCompressedPictures[i]);
        if (gImageDescriptions[i])
            DisposeHandle ((Handle)gImageDescriptions[i]);
    }
    DisposeGWorld (spritePlane);
}

© 1998 Apple Computer, Inc.

| Previous | Chapter Contents | Chapter Top | Next |